<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/10
  Time: 11:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库调度模态框</title>
</head>
<body>
    <form id="dispathchgatherform">
        <div class="modal-header">
            <input type="submit" class="btn btn-default" value="提交">
            <button class="close" data-dismiss="modal">退出</button>
        </div>
        <div class="modal-body">
            <div class="row">
                <div  class="col-md-offset-5"><h2><strong>入库调度单</strong></h2></div>
            </div>
            <br>
            <br>
            <br>
            <div class="row">
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>入库单编号:</td>
                            <td><input type="text" readonly id="gatherIddangmodal" style="outline: none;border:none"></td>
                        </tr>
                        <tr>
                            <td>产品名称:</td>
                            <td><input type="text" readonly id="productNamedangmodal" style="outline: none;border:none"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>产品编号:</td>
                            <td><input type="text" readonly id="productIddd" style="outline: none;border:none"></td>
                        </tr>
                        <tr>
                            <td>成本价:</td>
                            <td><input type="text" readonly id="costPricedd" style="outline: none;border:none"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <br><br>
            <div style="height:40%;">
                <table  id="dipathchgahtermodaltab">

                </table>
            </div>
            <br><br>
            <div class="row">
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>登记人:</td>
                            <td><input type="text" id="registerdd" style="outline:none;border: none;border-bottom:1px black dashed"></td>
                        </tr>
                        <tr>
                            <td>应入库:</td>
                            <td><input type="text" id="amountdd" readonly style="outline:none;border: none"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>应入库成本:</td>
                            <td><input type="text" id="subtotaldd" style="outline:none;border: none"></td>
                        </tr>
                        <tr>
                            <td>登记时间:</td>
                            <td><input type="text" id="registerTimedd" readonly style="outline:none;border: none"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <br>
            <br>
            <br>
        </div>
    </form>

        <script>
            //加载数据
            $(function () {
                    var datetimestack;
                    //点击获取当前时间
                    $.get("queryCellByDate.action",function (data) {
                        datetimestack=data.datetime;
                    },"json")
                    $("#dipathchgahtermodaltab").bootstrapTable({
                        contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                        striped: true,//是否显示隔行变色
                        cache: false,//是否缓存
                        pagination: false,//是否显示分页
                        sortable: false,//是否显示排序
                        clickToSelect: true,//是否启用点击选中行
                        uniqueId:"id",//每一行的唯一标识，一般为主键列,
                        columns:[
                            {
                                field:"",
                                title:"序号",
                                formatter:function (value,row,index) {
                                    return Number(index)+1
                                }
                            },
                            {
                                field:"amount",
                                title:"当前存储量",

                            },
                            {
                                field:"maxCapacityAmount",
                                title:"当前可存放数量",

                            },
                            {
                                field:"",
                                title:"本次入库数量",
                                formatter:function (value,row,index) {
                                    return "<input type='text' required id='numsdd' style='outline:none;border:none;background-color: silver''>"
                                }
                            },
                        ]
                    });
                    var productId='${param.productId}'
                    var ids='${param.ids}'
                    //根据产品编号查询
                    $.post("queryGatherDetailsByproductId.action",{"productId":productId,"ids":ids},function (data) {
                        console.log(data)
                        //赋值
                        //入库单编号
                        $("#gatherIddangmodal").val(data.gather.gatherId)
                        //产品名称
                        $("#productNamedangmodal").val(data.productName)
                        //产品编号
                        $("#productIddd").val(data.productId)
                        //成本价
                        $("#costPricedd").val(data.costPrice)
                        //登记人
                        $("#registerdd").val(data.gather.register)
                        //应入库
                        $("#amountdd").val(data.amount)
                        //应入库成本
                        $("#subtotaldd").val(data.subtotal)
                        //登记时间
                        $("#registerTimedd").val(datetimestack)
                        var arr=[]
                        arr.push(data.cell)
                        console.log(arr)
                        $("#dipathchgahtermodaltab").bootstrapTable("load",arr)
                    },"json")
            })

            //提交
            $("#dispathchgatherform").validate({
                submitHandler:function () {
                    //验证数字
                    var reg=/^[0-9]*$/
                    if(!reg.test($("#numsdd").val())){
                        alert("请输入正确的数字")
                        return
                    }
                    if(Number($("#amountdd").val())!=Number($("#numsdd").val())){
                        alert("入库数量不匹配")
                        return;
                    }
                   var amount=$("#numsdd").parent().parent().find("td").eq(1).text()
                   var maxCapacityAmount=$("#numsdd").parent().parent().find("td").eq(2).text()
                   var csk=(Number(maxCapacityAmount)-Number(amount))
                   if(Number($("#numsdd").val())>=csk){
                        alert("库存上线")
                        return;
                   }
                   //获取值当前入库的库存做修改
                  /* var gatherDetails={
                        "productId":$("#productIddd").val(),
                        "amount":Number(amount)+Number($("#numsdd").val()),
                        "maxCapacityAmount":maxCapacityAmount-(Number(amount)+Number($("#numsdd").val())),
                        "registerTime":$("#registerTimedd").val()
                    } */
                    var gatherDetails={
                        "productId":$("#productIddd").val(),
                         "gatheredAmount":$("#numsdd").val()
                    }
                    //赋值给控制层
                    $.ajax({
                        url:"updateGatherDetailsCell.action",
                        data:JSON.stringify(gatherDetails),
                        contentType:"application/json",
                        type:"post",
                        dataType:"json",
                        success:function (data) {
                            alert(data.msg)
                            $("#dispathchgathermodals").modal("hide")
                            $("#dispathchgaherdangtab").bootstrapTable("refresh")
                            jiazaigather();
                        }
                    })

                }

            })
        </script>
</body>
</html>
